package Day01;

import java.util.Scanner;

public class Vigenere {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.print("Please input your plain text: ");
		char[] plainText = scanner.nextLine().toLowerCase().toCharArray();
		System.out.print("Please input your secret key: ");
		char[] secretKey = scanner.nextLine().toLowerCase().toCharArray();
		System.out.print("The cipertext is: ");
		System.out.println(encode(plainText, secretKey));
		scanner.close();

	}

	public static char[] encode(char[] plainText, char[] secretKey) {
		int index = 0;
		char[] rst = new char[plainText.length];
		for (int i = 0; i < plainText.length; i++) {
			rst[i] = (char) ((secretKey[index++%secretKey.length] - 'a' + plainText[i] - 'a') % 26 + 'a') ;
		}
		return rst;
	}
}
